import { LayerContainer } from "@/containers/LayersContainer.js";
import { FlashToneFilter } from "@/filters/FlashToneFilter.js";

export class Spriteset extends LayerContainer{
    constructor(){
        super();
        this.createFilters();
        this.createLayers();
    }

    createFilters(){
        this._flashFilter=new FlashToneFilter();
        this.filters=[this._flashFilter];
    }

    createLayers(){
        this.base=this.add('lower');
        this.upper=this.add('upper');
    }

    update() {
        super.update();
        this.updateScreenSprites();
        this.updateToneChanger();
        this.updatePosition();
    }
    updateScreenSprites() {
        let color = $gameScreen.flashColor();
        this._flashFilter.setFlashTone(...color);
        this._flashFilter.setFadeAlpha(255 - $gameScreen.brightness());
    }
    updateToneChanger() {
        let tone = $gameScreen.tone();
        this._flashFilter.setTone(...tone);
    }
    updatePosition() {
        let screen = $gameScreen;
        let scale = screen.zoomScale();
        this.scale.set(scale);
        this.x = Math.round(-screen.zoomX() * (scale - 1)+screen.shake());
        this.y = Math.round(-screen.zoomY() * (scale - 1));
    }
}